import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description: 公共驱动类，对驱动进行操作
 */
public class DriverUtil {
    // 不能让外界创建 DriverUtil 的实例对象
    private DriverUtil() {}

    // 创建全局驱动对象
    private static volatile EdgeDriver driver;

    // 获取 Driver 对象
    public static EdgeDriver getDriver() {
        if(driver == null) {
            synchronized (DriverUtil.class) {
                if(driver == null) {
                    EdgeOptions options = new EdgeOptions();
                    options.addArguments("--remote-allow-origins=*");
                    driver = new EdgeDriver(options);
                }
            }
        }
        return driver;
    }

    // 关闭驱动对象
    public static void quit() {
        driver.quit();
    }
}
